package com.lottery.im.module.contact.adapter;

import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.widget.ImageView;
import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.lottery.im.R;
import com.lottery.im.module.tim.model.FriendFuture;
import com.lottery.im.util.transformations.CropCircleTransformation;
import java.util.List;

public class FriendMrgMsgAdapter extends BaseQuickAdapter<FriendFuture, BaseViewHolder> {

  public FriendMrgMsgAdapter(@Nullable List<FriendFuture> data) {
    super(R.layout.item_friend_mrgmsg, data);
  }

  @Override protected void convert(BaseViewHolder helper, FriendFuture item) {

    ImageView ivPortrait = helper.getView(R.id.iv_portrait);
    Glide.with(mContext)
        .load(item.getFaceUrl())
        .apply(new RequestOptions()
            .bitmapTransform(new CropCircleTransformation())
            .placeholder(R.drawable.icon_conversation_de)
            .error(R.drawable.icon_conversation_de))
        .into(ivPortrait);
    helper.setText(R.id.tv_name, item.getName());
    String summary;
    if (TextUtils.isEmpty(item.getMessage())) {
      summary = "无";
    } else {
      summary = item.getMessage();
    }
    helper.setText(R.id.tv_summary, "添加理由:" + summary);

    switch (item.getType()) {
      case TIM_FUTURE_FRIEND_PENDENCY_IN_TYPE:
        // 未处理
        helper.setGone(R.id.btn_agree, true);
        helper.setGone(R.id.btn_refuse, true);
        helper.setGone(R.id.tv_status, false);
        break;
      case TIM_FUTURE_FRIEND_PENDENCY_OUT_TYPE:
        // 等待验证
        helper.setGone(R.id.btn_agree, false);
        helper.setGone(R.id.btn_refuse, false);
        helper.setGone(R.id.tv_status, true);
        helper.setText(R.id.tv_status, "待验证");
        break;
      case TIM_FUTURE_FRIEND_DECIDE_TYPE:
        // 已接受
        helper.setGone(R.id.btn_agree, false);
        helper.setGone(R.id.btn_refuse, false);
        helper.setGone(R.id.tv_status, true);
        helper.setText(R.id.tv_status, "已添加");
        break;
    }

    helper.addOnClickListener(R.id.btn_agree);
    helper.addOnClickListener(R.id.btn_refuse);
  }
}
